﻿using LiteBlog.Common.Components;
using LiteBlog.Components.Contracts;
using LiteBlog.Controllers.Contracts;
using LiteBlog.Controllers.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace LiteBlog.Controllers
{
    public class ScheduleController : BaseController, IScheduleController
    {
        private IBlogComp _blogComp;
        private IBackupComp _backupComp;

        public ScheduleController(IBlogComp blogComp, IBackupComp backupComp, ISettingsComp settingsComp, ICacheComp cacheComp)
            : base(settingsComp, cacheComp)
        {
            _blogComp = blogComp;
            _backupComp = backupComp;  
        }

        public IBlogComp BlogComponent
        {
            get
            {
                return _blogComp;
            }
        }

        public IBackupComp BackupComponent
        {
            get
            {
                return _backupComp;
            }
        }

        [Authorize]
        [PageExceptionFilter]
        public ActionResult Publish()
        {
            BlogComponent.PublishScheduled();
            return new EmptyResult();
        }

        [PageExceptionFilter]
        public ActionResult Backup()
        {
            var settings = SettingsComponent.Load();
            if (settings.ShouldBackup)
                BackupComponent.Backup();
            return new EmptyResult();
        }

        public void ResolveComponents()
        {
           
        }
    }
}
